﻿#region Copyright Notice
// 
// 
//  
//  Copyright (c) 2009-2011 Anindya Chatterjee
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// 
// 
#endregion
using System;
using System.Drawing;
using System.Linq;
using AbstractClass.Collections.Generic;
using NUnit.Framework;

namespace QuasarTest.Core
{
    [TestFixture]
    public class AVLTreeTest
    {
        #region Setup/Teardown

        [SetUp]
        public void Init()
        {
            _tree = new AVLTree<int>();
            _tree.AddRange(Enumerable.Range(0, 100));
        }

        #endregion

        private AVLTree<int> _tree;

        [Test]
        public void TestAdd()
        {
            Assert.AreNotEqual(_tree.Root.Value, 0);
            Assert.AreEqual(_tree.Root.Value, 63);
            Assert.AreEqual(_tree.Count, 100);
            int i = 100;
            for (int j = 0; j < 100; j++)
            {
                _tree.Add(++i);
            }
            Console.WriteLine(_tree.Root);

            Assert.AreEqual(_tree.Root.Value, 128);

            #region DrawTree

            var drawer = new BinaryTreeDrawer<int>();
            Bitmap image = drawer.DrawImage(_tree.Root);
            image.Save(@"C:\tree.png");

            #endregion
        }

        [Test]
        public void TestMinMax()
        {
            Assert.AreEqual(_tree.Min, 0);
            Assert.AreEqual(_tree.Max, 99);
        }

        [Test]
        public void TestRemove()
        {
            Assert.AreEqual(_tree.Count, 100);
            Assert.IsTrue(_tree.Contains(99));
            _tree.Remove(99);
            Assert.IsFalse(_tree.Contains(99));
            Assert.AreEqual(_tree.Count, 99);
        }
    }
}